<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0">
        <title>Mentoring - Login</title>
		
		<!-- Favicon -->
        <link rel="shortcut icon" type="image/x-icon" href="assets/img/favicon.png">

		<!-- Bootstrap CSS -->
        <link rel="stylesheet" href="assets/css/bootstrap.min.css">
		
		<!-- Fontawesome CSS -->
        <link rel="stylesheet" href="assets/css/font-awesome.min.css">
		
		<!-- Main CSS -->
        <link rel="stylesheet" href="assets/css/style.css">
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
		<script src="https://cdn.bootcdn.net/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
		<!--[if lt IE 9]>
			<script src="assets/js/html5shiv.min.js"></script>
			<script src="assets/js/respond.min.js"></script>
		<![endif]-->
		<script>
			let serverUrl = undefined;
			$.ajax({// 加载json文件读取配置
				type:"GET",
				url:"js/config.json",
				async:false,
				dataType:"json",
				success:function(res){
					serverUrl = res.serverUrl;
				}
			});
			console.log(serverUrl);
		</script>
    </head>
    <body>
	
		<!-- Main Wrapper -->
        <div class="main-wrapper login-body">
            <div class="login-wrapper">
            <div class="container">
                <div class="loginbox">
                    <div class="login-left">
							<img class="img-fluid" src="assets/img/logo-white.png" alt="Logo">
                        </div>
                        <div class="login-right">
							<div class="login-right-wrap">
								<h1>登陆系统</h1>

								<!-- Form -->
								<form id="loginForm">
									<div class="form-group">
										<input class="form-control" name="adminName" type="text" placeholder="登录名">
									</div>
									<div class="form-group">
										<input class="form-control" name="adminPass" type="password" placeholder="登陆密码">
									</div>
									<div class="form-group">
										<button class="btn btn-primary btn-block" type="button" id="loginBtn">登陆</button>
									</div>
								</form>
								<!-- /Form -->
								
								<div class="text-center forgotpass"><a href="javascript:void(0)" onclick="alert('请找管理员修改密码')">忘记密码</a></div>
								<div class="login-or">
									<span class="or-line"></span>

								</div>
								<script>
									var loginUrl = "http://localhost:8088/paper/admin/login";
									$("#loginBtn").click(function(){
										$.ajax({
											
											type:"post",
											url:loginUrl,
											data:$("#loginForm").serialize(),
											xhrFields: {  
												withCredentials: true  
											},  
											crossDomain: true,	
											success:function(res){
												//console.log(res);
												if(res.code==200){
													// 取出sessionid
													let sessionId = res.obj;
													// 将sessionid设置到cookie中。
													document.cookie="sessionid="+sessionId;
													location.href="index.html";
												}else{
													alert("用户名或密码错误，请重试");
												}
											}});
									});
								</script>
								
							</div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
		<!-- /Main Wrapper -->
		

		
		<!-- Bootstrap Core JS -->
        <script src="assets/js/popper.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
		
		<!-- Custom JS -->
		<script src="assets/js/script.js"></script>
		
    </body>
</html>